package com.attilax.up;

import java.io.File;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 

import com.attilax.core;
import com.attilax.Stream.Mapx;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.util.WebCfgRead;
import com.focustar.downRec.GvDownloadRecordSvs;
import com.focustar.downtask.GvDownloadTaskSvs;
import com.focustar.publish.service.Impl.PublishServiceImpl;

@Controller
public class sprmvc {
	
	public static void main(String[] args) {
		   ProcessInfo pri = new ProcessInfo();  
	       pri.setItemNum( 2);
	       pri.readSize = 3;
	      
	       core.log(   core.toJsonStr(pri));
	}
	Logger log = Logger.getLogger(sprmvc.class);
	static final ThreadLocal<Integer> threadLocal4listerInvkTimes=new ThreadLocal<Integer>();;
  	String upFileSavePath ="";
	private boolean upfinish=false;
	/**
	 * upload  上传文件
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
 
	private void setProcessLister(final HttpSession hs, ServletFileUpload upload) {
		upload.setProgressListener(new ProgressListener(){
			   public void update(long pBytesRead, long pContentLength, int pItems) {
				   ProcessInfo pri = new ProcessInfo();  
			       pri.setItemNum( pItems);
			       pri.readSize = pBytesRead;
			       pri.totalSize = pContentLength;
			  //     pri.show = pBytesRead+"/"+pContentLength+" byte";
			       pri.rate = Math.round(new Float(pBytesRead) / new Float(pContentLength)*100);
			 
			   //ati o81    
			       pri.show =String.valueOf(  pri.rate)+"%";
			   //    if(!upFileSavePath.equals(""))
			       pri.path=upFileSavePath;
			       /////end ati
			       hs.setAttribute("proInfo", pri);
			       int newtimes=threadLocal4listerInvkTimes.get()+1;				       
			       core.log("---- listerInvkTimes times:"+String.valueOf(newtimes));
			       core.log(   core.toJsonStr(pri));
			       threadLocal4listerInvkTimes.set(newtimes);
			      
			   }
			});
	}
	
	
	/**
	 * process 获取进度
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/feedbackApi4test", method = RequestMethod.GET)
	@ResponseBody
	public Object feedbackApi4test(HttpServletRequest request,
			HttpServletResponse response)   {
		
		new GvDownloadTaskSvs().op(null);
				return response;
	 
		
	}
	/**
	 * 
	@author attilax 老哇的爪子
		@since  o8o m_40_2   
	
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/publsTest", method = RequestMethod.GET)
	@ResponseBody
	public Object publsTest(HttpServletRequest request,
			HttpServletResponse response)   {
		String equipmentIds="1,2,3,9999"; // 30g branch
		int publishId=9;
		
		new PublishServiceImpl().op(Mapx.<String,Object>$().add("eqids", equipmentIds).add("pubid", publishId).toMap());
				return response;
	 
		
	}
	
	/**
	@author attilax 老哇的爪子
		@since  o81 2_53_52$

	 */
	private void kaka() {
		// attilax 老哇的爪子  2_53_52   o81 
		{}
		{}
		{}

	}
	
}
